//
//  SearchTopKeyView.swift
//  MyTest
//
//  Created by guanzhongwang on 2021/5/16.
//

import UIKit

class SearchKeyView: UIView {
    init(items:Array<NewsSearchTextModel>) {
        super.init(frame: .zero)
        var temp:UIView?
        for i in 0..<items.count {
            let key = SearchKeyLabel(item: items[i], index: i)
            addSubview(key)
            key.snp.makeConstraints({
                if temp == nil {
                    $0.top.equalTo(0)
                    $0.left.equalTo(0)
                }else{
                    if i%2 == 0 {
                        $0.left.equalTo(0)
                        $0.top.equalTo((temp?.snp.bottom)!).offset(15)
                    }else{
                        $0.right.equalTo(0)
                        $0.top.equalTo((temp?.snp.top)!)
                    }
                }
                $0.width.equalToSuperview().dividedBy(2)
                if i == items.count-1{
                    $0.bottom.equalTo(0)
                }
            })
            temp = key
        }
    }
    
    init(items:Array<NewsSearchTextModel>,count:Int) {
        super.init(frame: .zero)

    }
    
    required init?(coder: NSCoder) {
        fatalError()
    }
}
